<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <p>watch-侦听</p>
    <input type="text" v-model="num1">
    <input type="text" v-model="person.age">
  </div>
  <script src="../vue.js"></script>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        num1: 100,
        person: {
          name: 'Tom',
          age: 18
        }
      },
      // 选项，用来监听
      watch: {
        // 浅监听：函数的格式，有俩个参数
        // num1(newVal, oldVal) {
        //   console.log(newVal);
        //   console.log(oldVal);
        // },
        // person(newVal, oldVal) {
        //   console.log('person',newVal);
        //   console.log('person',oldVal);
        // }
        // ================== 以下是深监听 ====================
        person: { // 对象的格式
          // 是否开启深监听，默认关闭
          deep: true,
          // handler事件的处理器，类似callback
          handler(newVal) {
            console.log(newVal);
          }
        }
      }
    })
  </script>
</body>
</html>